<include file="public@header" />
<link href="__STATIC__/js/element/css/element.css" rel="stylesheet" type="text/css">
<script src="__STATIC__/js/vue.js"></script>
<script src="__STATIC__/js/element/js/element.js"></script>
<script src="__STATIC__/js/axios.min.js"></script>

<style type="text/css">
    .el-dialog__body{ padding-top: 0px;}
</style>
</head>

<body>
    <div id="app">
        
        <div class="wrap js-check-wrap">
            <ul class="nav nav-tabs">
                <?php $currentTab = 1 ;?>
                <include file="public/../company/nav" />
            </ul>   

            <form class="well form-inline margin-top-20" method="post" action="{:url('company/company_list')}">
                <input type="text" class="form-control" name="keyword" value="{$k['keyword']|default=''}" placeholder="请输入要搜索的关键词">
                行业：
                <select id="searchField" name="type" class="form-control">
                    <option value="">全部</option>
                    <foreach name = "type" item = "t">
                        <option value="{$t.id}" <?php if($t['id']==$k['type_id']){echo 'selected';}?>  >{$t.type_name}</option>
                    </foreach>
                </select>
                <input type="submit" class="btn btn-primary" value="搜索" />
            </form>    

            <table class="table table-bordered table-hover" style="text-align: center;">
                <thead>
                    <tr>

                        <th style="text-align: center;" >公司名称</th> 
                        <!-- th style="text-align: center;" >组织代码</th-->
                        <th style="text-align: center;" >所属行业</th>
                        <th style="text-align: center;" >注册时间</th>
                        <th style="text-align: center;">aid</th>
                        <th style="text-align: center;">key</th>
                        <th style="text-align: center;">appsecret</th>
                        <th style="text-align: center;">到期时间</th>
                        <th style="text-align: center;" >状态</th>
                        <th style="text-align: center;" >是否激活</th>
                        <th style="text-align: center;" >操作</th>
                    </tr>
                </thead>
                <tbody>
                    <volist name="list" id="vo">
                    <tr>
                        
                        <td <?php if($vo['frame_type']==1){echo 'onclick="getAccount('.$vo['id'].')"';}?> >{$vo.company_name}</td>
                        <!--td >{$vo.company_num}</td -->
                        <td>{$vo.company_type}</td>
                        <td>{$vo.create_time|date="Y-m-d : H:i:s",###}</td>
                        <td style="width:100px;word-break:break-all;" ><?php echo md5(md5($vo['id'].$vo['create_time'])); ?></td>
                        <td style="width:100px;word-break:break-all;"><?php echo md5($vo['id'].$vo['create_time']); ?></td>
                        <td style="width:100px;word-break:break-all;"><?php $appid = md5(md5($vo['id'].$vo['create_time'])); $key = md5($vo['id'].$vo['create_time']) ; echo md5(md5($vo['id'].$appid.$key.$vo['create_time'])); ?></td>
                        <td><input type="text" style="width: 95px;" readonly class="form-control voperiod js-bootstrap-date" name="" data-tag='{$vo.id}' value='{$vo.period|date="Y-m-d",###}'><!-- <a href="javascript:;"  class="btn btn-success btn-sm voperiodbtn"  style='display: none;'>修改</a> --></td>
                        <td>
                            <php>
                                if($vo['status']==0){
                                    echo '<a href="javascript:;" title="点击禁用" onclick="modifyStatus(1,'.$vo['id'].');" style="color:red;">已停用</a>';
                                }else if($vo['status']==1){
                                    echo '<a href="javascript:;" title="点击启用" onclick="modifyStatus(0,'.$vo['id'].');" >正常</a>';    
                                }else if($vo['status']==2){
                                    echo '<a href="javascript:;" title="点击启用"  style="color:red;">审核中。。。</a>';    
                                }else if($vo['status']==3){
                                    echo '<a href="javascript:;" title="点击启用"  style="color:red;">未通过审核</a>';    
                                }
                            </php>
                        </td>
                        <td>
                            <if condition="$vo['active'] eq 1">
                                已激活
                                <else />
                                未激活
                            </if>
                        </td>
                        <td style="text-align: left;">
                            <a class="btn btn-info btn-sm" @click="auth_manage({$vo.id})">授权设置</a>
                            <a class="btn btn-primary btn-sm" @click="handle_message_push({$vo.id})">消息推送设置</a>
                            <if condition="$vo.id neq 8">
                            <a class="btn btn-warning btn-sm" onclick="userlist( {$vo.id} , '{$vo.company_name}');">用户</a>
                            </if>
                            <a class="btn btn-info btn-sm" onclick="mishi( {$vo.id} , '{$vo.company_name}');">密匙</a>
                            <if condition="$vo['active'] eq 1">
                                <a href="{:url('admin/company/resetActive')}?id={$vo.id}" class="btn btn-success btn-sm js-ajax-delete" data-msg="确定要重置吗？" >激活重置</a>
                            </if>
                            <a class="btn btn-danger btn-sm" href="javascript:;" onclick="selectAccessVersions({$vo.versions_type},{$vo.id},'{$vo.company_name}');"><php> if($vo['versions_type']==0){echo '未添加';}else {echo $vo['versions_name'];}</php></a>
                            <a class="btn btn-danger btn-sm js-ajax-delete" data-msg="即将删除该公司所有信息：包括公司、角色、部门、用户等信息，确定删除？"  href="{:url('admin/company/deleteCompanyInfo')}?id={$vo.id}"  >删除</a>
                        </td>					
                    </tr>
                </volist>
                </tbody>
            </table>
            
            <div class="pagination">{$list->render()}</div>
        </div>
        <div id="versions_bar" style="display: none;">
            <div style="padding: 10px;">
                    <volist name="versions_list" id="vo" >
                    <div style="height: 30px;width: 350px;margin: 10px auto;overflow: hidden;text-indent: 10px;">
                        <input type="radio" name="versions" value="{$vo.id}">&nbsp;<span >{$vo.name}</span>
                    </div>
                    </volist>
            </div>
        </div>

        <div id="mishi-div" style="display:none;">
            <div style="padding: 10px;">
                <div class="col-md-12">
                    <table class="table table-bordered">
                        <tr>
                            <td width="50">服务端公钥</td>
                            <td><textarea class="form-control server-gy" rows="5" id="server-gy"></textarea></td>
                        </tr>
                        <tr>
                            <td width="50">服务端私钥</td>
                            <td><textarea class="form-control server-sy" rows="5" id="server-sy"></textarea></td>
                        </tr>
                        <tr>
                            <td width="50">客户端公钥</td>
                            <td><textarea class="form-control client-gy" rows="5" id="client-gy"></textarea></td>
                        </tr>
                        <tr>
                            <td width="50">客户端私钥</td>
                            <td><textarea class="form-control client-sy" rows="5" id="client-sy"></textarea></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <el-dialog title="权限设置" :visible.sync="dialogVisible" >
        <el-tabs v-model="activeName" >
            <el-tab-pane label="权限目录" name="first">

                <el-form ref="form" :model="authform" label-width="80px">
                    
                    <el-form-item label="授权目录:">
                      <el-checkbox-group v-model="authform.path">
                        <el-checkbox label="video" name="video">video</el-checkbox>
                        <el-checkbox label="payext" name="payext" >payext</el-checkbox>
                        <el-checkbox label="chat" name="chat">chat</el-checkbox>
                      </el-checkbox-group>
                    </el-form-item>
                    
                    <el-form-item>
                      <el-button type="primary" size="small" @click="authSubmit">确认</el-button>
                      <el-button  size="small" @click="dialogVisible=false;">取消</el-button>
                    </el-form-item>
                  </el-form>
            </el-tab-pane>
            <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
            <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
            <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
        </el-tabs>
        </el-dialog>
    </div>
	<script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/layer/layer.js"></script>
<script>

//状态更改
function modifyStatus(s,i)
{
	$.post("{:url('company/modifyStatus')}",{status:s,id:i},function(res){
		if(res.code==1){
			layer.msg('修改成功！');
			window.location.reload();
		}else{
			layer.alert('修改状态失败，请稍后再试！');
		}
	},'json');
}
//选择菜单授权版本
function selectAccessVersions(x,id,name)
{
    //设置当前选中的值
    $('#versions_bar').find('input[type=radio]').each(function(){
        if($(this).val()==x){
           $(this).prop('checked',true);
        }
    });
   var index = layer.open({
          type: 1,
          title: name+"权限版本选择",
          area: ['370px', '450px'],
          closeBtn: 1,
          btn:['保存','取消'],
          shadeClose: true,
          skin: 'yourclass',
          content: $('#versions_bar'),
          yes:function(){
            //点击提交
            //获取当前选中的项
            var current=x;
            $('#versions_bar').find('input[type=radio]').each(function(){
                if($(this).is(':checked')){
                    current= $(this).val();
                }
            });
             if(current==x){
                layer.msg('未做更改，请更改后在保存！');
             }else{
                //提交到数据库
                var url="{:url('company/ajax_change_access')}";
                $.ajax({url:url,data:{type:current,id:id},type:'post',dataType:'json',success:function(data){
                    if(data.status=="success"){
                        layer.close(index);
                        window.location.reload();
                    }
                    layer.msg(data.message);
                }});
             }
          }
      });
}

//更改到期时间
$('.voperiod').on('change',function(){
   // $(this).attr('readonly','readonly');
    var _this=$(this);
    layer.confirm('确定修改到期时间吗？',{title:'修改到期时间',btn:['修改','取消']},function(){
            $.get('{:url("company/modifyPeriod")}?id='+_this.data('tag')+'&period='+_this.val(),function(data){
                data=JSON.parse(data);
                layer.msg(data.message);
                if(data.status=='success'){
                    setTimeout(function(){
                        window.location.reload();
                    },800);
                }
            });
        },function(index){
            layer.close(index);
        });
});
var getAccount=function(id){
    $.get("{:url('company/getAccount')}?id="+id,function(data){
        layer.alert(data, {icon: 6,title:'ACCOUNT INFORMATION'});
    });
}

//密匙
var mishi = function( id , companyName ){
var mishidiv = $('#mishi-div').html();
$('#mishi-div').html('')
    $( '#server-gy' ).val('');
    $( '#server-sy' ).val('');
    $( '#client-gy' ).val('');
    $( '#client-sy' ).val('');
    layer.open({
        type: 1,
        title: '公司:'+companyName+' 秘钥设置',
        area:['700px','80%'],
        closeBtn: 1,
        btn:['保存','清除','取消'],
        shadeClose: true,
        skin: 'yourclass',
        content: mishidiv,
        yes:function(index){
            let url = '{:url("admin/company/saveMishi")}';
            var obj = {};
            obj [ 'server_gy' ] = $( '#server-gy' ).val();
            obj [ 'server_sy' ] = $( '#server-sy' ).val();
            obj [ 'client_gy' ] = $( '#client-gy' ).val();
            obj [ 'client_sy' ] = $( '#client-sy' ).val();
			console.log(obj);
            //保存数据
            $.post( url , { data:obj , id:id } ,function(res){
				var data = JSON.parse(res);
                let icon = ( data.code == 200 )? 1:5;
                layer.msg( data.message);
                if( icon == 1 ){
					$('#mishi-div').html(mishidiv);
                    layer.close(index);
                }
            } );
            
        },
		btn2:function(){
			$( '#server-gy' ).val('');
			$( '#server-sy' ).val('');
			$( '#client-gy' ).val('');
			$( '#client-sy' ).val('');
			return false;
		},
		end:function(){
			$('#mishi-div').html(mishidiv);
		}
    });
    let url = "{:url('admin/Company/getMishi')}";
    $.post( url , { id: id} ,function(res){
		res = JSON.parse(res);
		var data = res.data;
        $( '#server-gy' ).val(data.server_gy);
        $( '#server-sy' ).val(data.server_sy);
        $( '#client-gy' ).val(data.client_gy);
        $( '#client-sy' ).val(data.client_sy);
    } );
}

</script>

<script>
var userlist = function( id , companyName){
	layer.open({
		type:2,
		area: ['700px', '450px'],
		fixed: false, //不固定
		maxmin: true,
		btn:["关闭"],
		content: '{:url("admin/CompanyUser/index")}?cid='+id+'&name='+companyName
	});
}
</script>

<script>
    new Vue({
      el: '#app',
      data: function() {
        return { 
            visible: false,
            authform:{
                path:[]
            },
            company_id:'',
            activeName:'first',
            dialogVisible:false,
        }
      },
      mounted() {
         
      },
      methods: {
        auth_manage (id){
            this.dialogVisible = !this.dialogVisible;
            if (this.dialogVisible) {
                this.company_id = id
                this.get_auth();
            }
            
        },
        authSubmit(){
            axios.post('{:url("admin/Company/update_path")}', {
                id: this.company_id,
                authform:this.authform
            }).then( res=> {
              if (res.data.status == 'success') { 
                    this.dialogVisible  = false
                    this.$message.success("保存成功");
              }
            })
        },
        get_auth(){
            
            axios.post('{:url("admin/Company/get_auth")}', {
                id: this.company_id,
            }).then( res=> {
              if (res.data.status == 'success') { 

                    this.authform = res.data.data
              }
            })
        },
        //配置消息推送页面
          handle_message_push(id){
              let that = this;
              let url = "{:cmf_plugin_url('MessagePush://admin_index/index')}?id="+id;
              layer.open({
                  type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                  ,title: '消息配置'//层的标题
                  ,shadeClose: false//是否点击遮罩关闭
                  ,shade: 0.8//遮罩
                  ,area: ['70%', '60%']//宽高
                  ,fixed:false//固定
                  ,content: url //iframe的url
                  ,end: function () {

                  }
              });
          },
      }
    })
  </script>
</body>
</html>